<?php
namespace app\warehouse\model;

use think\Model;

class Warehouse extends Model
{
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    public function hasShop()
    {
        return $this->hasOne('app\shop\model\Shop', 'id', 'shop_id');
    }

    public static function getSelect($data = [], $id = 0, $level = 0)
    {
        if (empty($data)) {
            return '';
        }
        $str = $separ = '';
        if ($level > 0) {
            for ($i=0; $i < $level; $i++) {
                $separ .= '&nbsp;&nbsp;&nbsp;';
            }
            $separ .= '┣&nbsp;';
        }

        foreach ($data as $k => $v) {
            if ($id == $v['id']) {
                $str .= '<option value="'.$v['id'].'" selected>'.$separ.$v['name'].'</option>';
            } else {
                $str .= '<option value="'.$v['id'].'">'.$separ.$v['name'].'</option>';
            }
            if (isset($v['childs'])) {
                $str.= self::getSelect($v['childs'], $id, $level+1);
            }
        }
        return $str;
    }
    /**
     * 获取仓库类型 function
     *
     * @param [int] $id  仓库id
     * @return void
     */
    public function warehouseType($id)
    {
        $type = $this->where('id',$id)->value('type');
       
        return  $type;
        
    }
}
